﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication6
{
    class RecursiveFibonaci
    {

        private int i_n;
        private float f_elapsetime;
        private long l_fibonaci;


        /// <summary>
        /// Constructor of RecursiveFibonaci Class
        /// </summary>
        /// <param name="i_n"></param>
        public RecursiveFibonaci(int n)
        {
            this.i_n = n;
        }


        /// <summary>
        /// Get i_n
        /// </summary>
        /// <returns>i_n</returns>
        public int Getn()
        {
            return this.i_n;
        }


        /// <summary>
        /// Set the value of i_n;
        /// </summary>
        /// <param name="n"></param>
        public void Setn(int n)
        {
            this.i_n = n;
        }


        /// <summary>
        /// Compute the Fibonaci[i]
        /// </summary>
        /// <param name="i"></param>
        /// <returns>Fibonaci[i]</returns>
        public long Fib(int i)
        {
            if (i == 0)//Fib[0] = 0
            {
                return 0;
            }
            if (i == 1)//Fib[1] = 1
            {
                return 1;
            }
            return Fib(i - 1) + Fib(i - 2);//Fib[i] = Fib[i-1] + Fib[i-2]
        }


        /// <summary>
        /// Get the f_elapsetime value
        /// </summary>
        /// <returns>f_elapsetime</returns>
        public float GetElapseTime()
        {
            return this.f_elapsetime;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public long Get_Fibonaci()
        {
            return this.l_fibonaci;
        }


        /// <summary>
        /// Count the time that use to get the result Fib[n]
        /// </summary>
        public void Implement()
        {
                DateTime dt_start = new DateTime();
                DateTime dt_end = new DateTime();
                dt_start = DateTime.Now;
                this.l_fibonaci = Fib(i_n);
                dt_end = DateTime.Now;
                TimeSpan ts_timespans = dt_end - dt_start;
                this.f_elapsetime = ts_timespans.Seconds*1000 + ts_timespans.Milliseconds;            
        }
    }
}
